﻿using CPPEI.Coolzon.Common.Startup;
using CPPEI.Coolzon.Configuration;
using CPPEI.WPF.Core;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Windows;

namespace CPPEI.Coolzon.Launcher
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : XApplication
    {
        /// <summary>
        /// true:更新完成之后重新运行主程序
        /// false:更新完成之后不需要重新启动
        /// </summary>
        public static bool IsNeedRestart = false;

        public App()
            : base("CPPEI", "Coolzon", "Launcher", "启动程序")
        {
            Coolzon.Common.Logger.InitByLogDirectory(CZEnvironment.GetLogDirectory());
            XConfigUtil.Init(CZEnvironment.Instance, CZEnvironment.GetEnvironmentFilePath());
        }

        /// <summary>
        /// /restart y/n
        /// "y"代表更新完成之后重新运行主程序，"n"或者null代表更新完成之后不需要重新启动
        /// 
        /// </summary>
        /// <param name="startupParams"></param>
        protected override void OnXStartup(StartupParamCollection startupParams)
        {
            if (string.Equals(startupParams.GetValue("restart"), "y", StringComparison.CurrentCultureIgnoreCase))
            {
                IsNeedRestart = true;
            }

            if (StartupParams.GetValue("p") == string.Empty)
            {
                StartupUri = new Uri("UI_Default/DefaultWindow.xaml", UriKind.Relative);
            }
            else
            {
                StartupUri = new Uri("UI_Mini/MiniWindow.xaml", UriKind.Relative);
            }
        }
    }
}
